Skip to content

fix(knowledge-turso): a build that continues after dropSource cannot bring the dropped source back - #38051

Draft
objectstack-fleet[bot] wants to merge 3 commits into
mainfrom
claude/area-o1C-37953
Draft

objectstack-fleet[bot] wants to merge 3 commits into
mainfrom
claude/area-o1C-37953

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

repo:objectstack#1 · os-elon-musk · session_016WV4cwPhGV4g9p1BGQaZbP

Fixes #37953

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:使用 Turso 知识库存储的部署里,删除一个知识源时如果别处还有一次对它的重建在跑,以前那次重建的下一页会把知识源悄悄"复活";现在删掉的就没了,那次重建会被拒绝并停下。删除之后新开始的重建照常工作。
  • 为什么做:这是 AI 知识库"索引分代与重建"专项的跟进,把 pgvector 存储上已经修好的同一个并发漏洞在 Turso 存储上补上,让两种存储行为一致。
  • 出错会怎样:最坏的情况是一次正在进行的重建被拒绝,需要再重建一次;改动只在 Turso 存储里,可以直接撤回。
  • 要你做什么:无。

What changes

IKnowledgeAdapter.dropSource (packages/spec/src/contracts/knowledge-adapter.ts) removes "every generation, the one under construction included", and afterwards "a source registered again under the same key is built from nothing". On the turso store a build that was under way when its source was dropped broke that: its next page reached writeTarget, which found no generation and opened a new active one (the rule that a source holding nothing takes the first fingerprint it is handed), and the rest of the walk landed there. The contract sentence is right and is unchanged. The adapter is fixed, mirroring the pgvector fix that landed for the same defect class.

  1. A build carries the generation it began. beginBuild now records, per source, the generation the build writes into: the one it opened, the one under construction it joined, or the active one it rebuilds inside. The record is the generation's number, the time its row was made (created_at, already a column of knowledge_generation, millisecond grain) and its fingerprint. The number alone is not enough on turso: the next generation is the source's highest plus one, so after a drop, or after one build replaces another, a new generation takes the same number again (pinned: a replacing build's generation is 2 again). Nothing new is stored; the table's shape is unchanged.
  2. A build's writes, listing and completion go only to that generation. A call carrying ctx.reason === 'reindex' from a build this adapter began goes to its generation and to no other (writeTarget). When that generation is no longer active or under construction (the source was dropped in this process or another, or another build under another fingerprint replaced it), the build ends and the call is refused LOCK_CONFLICT (409), the code and status pgvector answers. completeBuild makes the same check first. Before, a completion with no write since the drop threw a plain Error with no code.
  3. A page whose embedding was under way when the drop committed is written nowhere. writePassages already re-reads the planned generation inside its write transaction; that check now also compares created_at, so a later generation under the same number is never taken for the planned one. The batch is planned again, and the build's retry is refused by (2).
  4. A build that begins after the drop works as before: it builds the source from nothing.

turso has no builder lock and its drop is one SQLite-serialized transaction, so pgvector's first case (a drop missing a generation that a concurrent transaction opened) has no turso counterpart, as the card says.

Serial with F6. The approximate-index card (F6) edits the same file's search path and completeBuild's start and has no PR yet. This PR stays out of the search code. A probe git merge-tree of this branch with that branch's head (84f82932d4) merges cleanly. Whichever lands second merges main.

Tests

New top-level describe in src/__tests__/acceptance.test.ts (the package's existing harness file), on :memory: and on a file: URL. Two adapters stand for two processes: each keeps its own builds, and on a file each has its own connection to the same database.

  • A build beside the active generation, inside it, and of a source that held nothing, then a drop in the other process: the build's write, listing and completion (one cell each, 9 cells) are refused LOCK_CONFLICT 409; the store holds no generation row and no passage table for the source; indexStatus answers {}; a build that begins afterwards builds the source from nothing and is searched.
  • A drop in the build's own process ends the build the same way.
  • A page whose embedding was under way when the drop committed is written nowhere.
  • A build another process replaced under another fingerprint is ended the same way, and the replacing build completes and is searched.
  • A generation that takes a dropped build's number, under another fingerprint and under the same fingerprint made later, is never that build's.
  • Through KnowledgeService: a walk whose source the other process drops after its first page stops (ok: false, indexed: 100, one page written), leaves nothing, and the next walk builds the source from nothing (ok: true, indexed: 250).
Local readings at open time: NOT MEASURED (the shared verify lock)

NOT MEASURED: the package's tests, typecheck, the two ablations and the derived gate list. Reason: the container's shared verify lock never reached this branch in five queued attempts (about 53 minutes, each VERDICT queue-timeout (exit 99) · never acquired, the place kept as a slot); the holder throughout was one full dogfood run (pid 7724, held 2653 s at the last reading), with three callers ahead of this one. The run that waits for the lock is queued as: the package's vitest run, then the ablations below, then the dependency-closure build, typecheck, and every command dispatch-gates --commands derives for this diff. Its readings go to the report comment on the card. CI's Test Core runs this package's test files, acceptance.test.ts included (it has no live dependency), and TypeScript Type Check its typecheck.

Ablations queued (each mutates the committed adapter, runs the new describe, then restores and checks git diff HEAD is empty; the tests import src, so no dist is involved):

  • the old writeTarget path (the build branch disabled): the write, listing, same-process, embedding, replaced and reused cells are expected red, the completion cells green;
  • completeBuild's first check deleted: the completion cells are expected red.
Overlap

node scripts/pm/overlap-check.mjs at 82ee427: VERDICT clean exit 0 (origin/main 8d34c44 merges cleanly; 0 open PR heads share a file). F6 has no PR, so the probe above (git merge-tree --write-tree against its branch head 84f8293, empty attribute source) is the reading for it: exit 0.

Acceptance notes

  • Boundary, not changed here: writes outside a build (reason other than reindex, event sync) are not fenced. One that arrives after a drop opens a fresh active generation, as for any source that holds nothing; the service stops sending them once the source is unregistered in that process. Same boundary as pgvector.
  • Boundary, not changed here: the build's removals (delete, the walk's purge) are not fenced: they remove from every generation of the source, and after a drop there is none, so nothing comes back.
  • Boundary: a build whose walk failed never calls completeBuild, and turso has no builder lock whose idle time would end it, so its record stays until the source's next beginBuild in that process replaces it. A capped walk (limit, no beginBuild) of that source in that process goes to the same generation it would have gone to anyway; after a drop it is refused once and the record is gone.
  • Boundary: two generations of one source with the same number, the same fingerprint and a row made in the same millisecond cannot be told apart. That needs a drop and a new build of the source under the same fingerprint inside one millisecond of the first build's begin; such a build writes the same source under the same fingerprint.
  • buildEnded text: one sentence, no SQL; operator text in remedy. No consumer parses it.

Verification

Read first:

  1. turso-adapter.ts, the build branch at the top of writeTarget: every call of a walk goes through it, and a wrong match would refuse a healthy build.
  2. completeBuild: the check that comes first in its transaction.
  3. beginBuild: which generation is recorded (the one under construction taken up first, then the active one, else the one opened).

Two-minute check: pnpm --filter @objectstack/knowledge-turso exec vitest run --maxWorkers=2 src/__tests__/acceptance.test.ts -t "dropped while it runs". Expected: 30 passed (15 cells on each of the two store kinds).


Generated by Claude Code

…y to the generation it began

A build that continued after dropSource found no generation and opened a
fresh active one, bringing the dropped source back. The adapter now keeps
the generation each build began (its number, the time its row was made and
its fingerprint) and refuses the build's later calls LOCK_CONFLICT once
that generation is gone.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 1 package(s): @objectstack/knowledge-turso, touching 17 documentable anchor(s). ⚠️ 1 changed file(s) yielded no anchor (packages/plugins/knowledge-turso/README.md), so the pages documenting them are NOT COVERED by this run — this is not a clean bill of health for those files.

9 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/ai/knowledge-rag.mdx (via LOCK_CONFLICT (symbol, a top-level const object), LOCK_CONFLICT (literal, a string literal in LOCK_CONFLICT))
  • content/docs/api/error-catalog.mdx (via LOCK_CONFLICT (symbol, a top-level const object), LOCK_CONFLICT (literal, a string literal in LOCK_CONFLICT))
  • content/docs/data-modeling/currency.mdx (via /:object/import/jobs (route, bridged from symbol createdAt — its route source's handler names it))
  • content/docs/data-modeling/import-mappings.mdx (via /:object/import/jobs (route, bridged from symbol createdAt — its route source's handler names it))
  • content/docs/frontend/data-objectstack.mdx (via createdAt (symbol, a field of interface GenerationRow), createdAt (literal, a string literal in BuildMark))
  • content/docs/frontend/plugins/plugin-detail.mdx (via createdAt (symbol, a field of interface GenerationRow), createdAt (literal, a string literal in BuildMark))
  • content/docs/permissions/system-context.mdx (via /:object/import/jobs (route, bridged from symbol createdAt — its route source's handler names it))
  • content/docs/protocol/knowledge.mdx (via LOCK_CONFLICT (symbol, a top-level const object), beginBuild (symbol, a method of class TursoKnowledgeAdapter), completeBuild (symbol, a method of class TursoKnowledgeAdapter), LOCK_CONFLICT (literal, a string literal in LOCK_CONFLICT))
  • content/docs/protocol/objectql/state-machine.mdx (via /:object/import/jobs (route, bridged from symbol createdAt — its route source's handler names it))
What this run could not see
  • 1 changed file(s) yielded no anchor (packages/plugins/knowledge-turso/README.md) — pages documenting those are invisible to this run
  • 2 name(s) were too generic to anchor anything (single lowercase words)
  • the SDK route bridge reached 69 of 252 client-bound route-ledger rows — the other 183 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 183: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 124 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 2 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json b4c99b8dd17b4038b9b5891c87c998ad6e022bb5 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 11e6e9dc38c0b0ed566d8c95f236f4d686ed4c8c — the merge of head 576a37667fd6c6430c8c1b70373214e54a71e7bb into base b4c99b8dd17b4038b9b5891c87c998ad6e022bb5, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 11e6e9dc38c0b0ed566d8c95f236f4d686ed4c8c && git checkout 11e6e9dc38c0b0ed566d8c95f236f4d686ed4c8c
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin b4c99b8dd17b4038b9b5891c87c998ad6e022bb5 576a37667fd6c6430c8c1b70373214e54a71e7bb && git checkout -B drift-repro b4c99b8dd17b4038b9b5891c87c998ad6e022bb5 && git merge --no-ff 576a37667fd6c6430c8c1b70373214e54a71e7bb

node scripts/docs-audit/affected-docs.mjs --json b4c99b8dd17b4038b9b5891c87c998ad6e022bb5

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs b4c99b8dd17b4038b9b5891c87c998ad6e022bb5 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

…finished build away

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4cwPhGV4g9p1BGQaZbP

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Review follow-ups of PR #37942: knowledge-turso — a build that continues after dropSource reopens the dropped source

2 participants